﻿

#include "NetMsgHandler.h"

#include "NetPetHandler.h"

#include "CreatureManager.h"

RECV_MSG_PET_INFO gMsgPetInfo;


fint32				NetSetPetTypeHandler( GamePlayer* player , netMsgHead* head )
{
	CHECKMSG( SEND_MSG_SET_PET_TYPE )

	player->SetPetType( msg->ID , msg->PetType );
    
    return GAME_NO_ERROR;
}


fint32				NetSetPetNameHandler( GamePlayer* player , netMsgHead* head )
{
	CHECKMSG( SEND_MSG_SET_PET_NAME )
    
	msg->Name[ MAX_NAME - 1 ] = '\0';

	player->SetPetName( msg->ID , msg->Name );
    
    return GAME_NO_ERROR;
}


fint32				NetPetInfoHandler( GamePlayer* player , netMsgHead* head )
{
    CHECKMSG( SEND_MSG_PET_INFO )
    
	GamePetMap& pMap = player->GetPetMap();
	GamePetMapIter iterEnd = pMap.end();

	gMsgPetInfo.Count = 0;

	for ( GamePetMapIter iter = pMap.begin() ; iter != iterEnd ; ++iter )
	{
		gMsgPetInfo.Data[ gMsgPetInfo.Count ].Data = iter->second.GetData();
		gMsgPetInfo.Data[ gMsgPetInfo.Count ].Data.Base = iter->second.GetFightData().Base;
		gMsgPetInfo.Data[ gMsgPetInfo.Count ].ID = gMapPetPhotoID[ iter->second.GetEnemyBase()->intValue[ GEBIV_ID ] ].id;
		gMsgPetInfo.Data[ gMsgPetInfo.Count ].Photo = gMapPetPhotoID[ iter->second.GetEnemyBase()->intValue[ GEBIV_ID ] ].photo;
		gMsgPetInfo.Count++;
	}

	gMsgPetInfo.size = sizeof( netMsgHead ) + sizeof( fint32 );
	gMsgPetInfo.size += gMsgPetInfo.Count * sizeof( PetSynData );

	player->PackMsg( &gMsgPetInfo );
	player->SendMsg();

    return GAME_NO_ERROR;
}

